import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  // 静态路由表
  routes: constantRoutes || []
}
const mutations = {
  // 如果需要添加新的路由
  setRoutes(state, otherRoutes) {
    state.routes = [
      ...constantRoutes,
      ...otherRoutes
      // { path: '*', redirect: '/404', hidden: true }
    ]
  }
}
const actions = {
  // 筛选路由权限
  filterRoutes({ commit }, menus) {
    // console.log(menus)
    const otherRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    // console.log(otherRoutes)
    commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}
export default {
  namespaced: true,
  state, mutations, actions
}
